﻿using System;
using System.Linq;
using Fabrication.Tests.TestClasses;
using NUnit.Framework;

namespace Fabrication.Tests
{
    [TestFixture]
    public class default_providers
    {
        [Test]
        public void should_build_item_with_complex_properties()
        {
            var builtItem = new FabricationScope().Generate<SinglePropertyClass<SinglePropertyClass<string>>>();
            Assert.That(builtItem.Value.Value, Is.EqualTo("Value1"));
        }

        [Test]
        public void should_set_default_values_for_public_string_properties_if_no_rules_defined()
        {
            var builtItem = new FabricationScope().Generate<SinglePropertyClass<string>>();
            Assert.That(builtItem.Value, Is.EqualTo("Value1"));
        }

        [Test]
        public void should_set_default_values_for_public_int_properties_if_no_rules_defined()
        {
            var builtItem = new FabricationScope().Generate<SinglePropertyClass<int>>();
            Assert.That(builtItem.Value, Is.EqualTo(1));
        }

        [Test]
        public void should_set_default_values_for_public_bool_properties_if_no_rules_defined()
        {
            var builtItem = new FabricationScope().Generate<SinglePropertyClass<bool>>();
            Assert.That(builtItem.Value, Is.False);
        }

        [Test]
        public void should_set_default_values_for_public_date_properties_if_no_rules_defined()
        {
            var builtItem = new FabricationScope().Generate<SinglePropertyClass<DateTime>>();
            Assert.That(builtItem.Value, Is.EqualTo(DateTime.Today));
        }

        [Test]
        public void should_set_unique_values_for_public_guid_properties_if_no_rules_defined()
        {
            var builtItems = new FabricationScope().Generate<SinglePropertyClass<Guid>>(10);
            var distinctIds = builtItems.Select(x => x.Value).Distinct();
            Assert.That(distinctIds.Count(), Is.EqualTo(builtItems.Count()));
        }

        [Test]
        public void should_use_separate_counters_for_separate_properties()
        {
            var builtItem = new FabricationScope().Generate<StringAndInteger>();
            Assert.That(builtItem.Name, Is.EqualTo("Name1"));
            Assert.That(builtItem.Number, Is.EqualTo(1));
        }

        [Test]
        public void should_populate_multiple_properties_of_same_type()
        {
            var builtItem = new FabricationScope().Generate<DoublePropertyClass<string>>();
            Assert.That(builtItem.FirstValue, Is.EqualTo("FirstValue1"));
            Assert.That(builtItem.SecondValue, Is.EqualTo("SecondValue1"));
        }

        [Test]
        public void should_build_single_item()
        {
            var builtItem = new FabricationScope().Generate<DefaultConstructor>();
            Assert.That(builtItem, Is.InstanceOf<DefaultConstructor>().And.Not.Null);
        }
    }
}